package io.renren.modules.sys.controller;

import java.util.Arrays;
import java.util.Map;

import io.renren.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.sys.entity.TiananSubmitEntity;
import io.renren.modules.sys.service.TiananSubmitService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;


/**
 * 提案
 *
 * @author Mark
 * @email sunlightcs@gmail.com
 * @date 2021-03-21 20:42:15
 */
@RestController
@RequestMapping("sys/tianansubmit")
public class TiananSubmitController {
    @Autowired
    private TiananSubmitService tiananSubmitService;


    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = tiananSubmitService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 列表
     */
    @RequestMapping("/listled")
    public R listled(@RequestParam Map<String, Object> params) {
        return R.ok().put("list", tiananSubmitService.list(params));
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id) {
        TiananSubmitEntity tiananSubmit = tiananSubmitService.getById(id);

        return R.ok().put("tiananSubmit", tiananSubmit);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("sys:tianansubmit:save")
    public R save(@RequestBody TiananSubmitEntity tiananSubmit) {
        tiananSubmitService.save(tiananSubmit);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("sys:tianansubmit:update")
    public R update(@RequestBody TiananSubmitEntity tiananSubmit) {
        ValidatorUtils.validateEntity(tiananSubmit);
        tiananSubmitService.updateById(tiananSubmit);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("sys:tianansubmit:delete")
    public R delete(@RequestBody Integer[] ids) {
        tiananSubmitService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
